/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.google.code.peersim.protocols;

import com.google.code.peersim.metrics.EuclideanMetric;
import peersim.core.Node;
import peersim.core.Protocol;

/**
 * This {@link Protocol} implementation simply holds a bidimensional coordinate
 * for the {@link Node} it is assigned to. This protocol also implements the
 * {@link EuclideanMetric.EuclideanMetricMeasurableIfc}. This allows other components
 * to use its instances as input for the {@link EuclideanMetric} class when measuring
 * distances between node pairs.
 *
 * @author frusso
 * @version 0.1
 * @since 0.1
 */
public final class TwoDimCoordinatesProtocol implements Protocol, EuclideanMetric.EuclideanMetricMeasurableIfc {

  // the coordinates
  private int x, y;

  /**
   * Constructor.
   *
   * @param prefix Prefix for accessing configuraiton parameters
   */
  public TwoDimCoordinatesProtocol(String prefix) {
    super();
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public final int getX() {
    return x;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public final int getY() {
    return y;
  }

  /**
   * Assigns the {@code X} coordinate.
   * @param x
   */
  public final void setX(int x) {
    this.x = x;
  }

  /**
   * Assigns the {@code Y} coordinate.
   * @param y
   */
  public final void setY(int y) {
    this.y = y;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public final Object clone() {
    try {
      return super.clone();
    } catch(CloneNotSupportedException e) {
      throw new RuntimeException("Cloning failed. See nested exceptions, please.", e);
    }
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public String toString() {
    return "["+x+","+y+"]";
  }
}